package com.ruoyi.tester.domain;

import com.ruoyi.common.annotation.Excel;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author SongJun
 * @description TODO:
 * @date 2023/10/17 17:39
 */
public class TesterTaskInterfaceRelationOut {
    /** 关系id */
    private Long relationId;

    /** 任务id */
    private Long taskId;
    private String taskName;

    /** 接口id */
    private Long interfaceId;
    private String interfaceName;

    /** 描述信息 */
    private String description;

    /** 主机 */
    private String host;

    /** 端口 */
    @Excel(name = "端口")
    private Integer port;

    /** 依赖关系id(以逗号分隔) */
    private String dependRelationIds;
    //依赖关系描述
    private String dependRelationDesc;

    /** 依赖参数 */
    private String dependParam;

    /** content_type */
    private String contentType;

    /** query参数 */
    private String queryParam;

    /** body参数 */
    private String bodyParam;

    /** path参数 */
    private String pathParam;

    /** 登录配置id */
    private Long loginConfigId;
    //登录配置描述
    private String loginConfigDesc;

    /** 状态（0正常 1停用） */
    private String status;

    public TesterTaskInterfaceRelationOut(TesterTaskInterfaceRelation item,
                                          Map<Long, TesterTask> taskMap,
                                          Map<Long, TesterInterface> interfaceMap,
                                          Map<Long, TesterTaskInterfaceRelation> dependMap,
                                          Map<Long, TesterLoginConfig> loginMap) {
        this.relationId = item.getRelationId();
        this.taskId = item.getTaskId();
        if (taskMap.containsKey(taskId)) {
            this.taskName = taskMap.get(taskId).getDesc();
        }
        this.interfaceId = item.getInterfaceId();
        if (interfaceMap.containsKey(interfaceId)) {
            this.interfaceName = interfaceMap.get(interfaceId).getDesc();
        }
        this.description = item.getDescription();
        this.host = item.getHost();
        this.port = item.getPort();
        this.dependRelationIds = item.getDependRelationIds();
        this.dependParam = item.getDependParam();
        this.contentType = item.getContentType();
        this.queryParam = item.getQueryParam();
        this.bodyParam = item.getBodyParam();
        this.pathParam = item.getPathParam();
        this.loginConfigId = item.getLoginConfigId();
        if (loginMap.containsKey(loginConfigId)) {
            this.loginConfigDesc = loginMap.get(loginConfigId).getDesc();
        }
        this.status = item.getStatus();

        if (StringUtils.hasLength(this.dependRelationIds)) {
            String[] split = this.dependRelationIds.split(",");
            for (String s : split) {
                if (StringUtils.hasLength(s.trim())) {
                    TesterTaskInterfaceRelation relation = dependMap.get(Long.valueOf(s.trim()));
                    if (relation != null) {
                        if (this.dependRelationDesc == null) {
                            this.dependRelationDesc = "[" + relation.getDescription() + "]";
                        } else {
                            this.dependRelationDesc += "<br>";
                            this.dependRelationDesc += "[" + relation.getDescription() + "]";
                        }
                    }
                }
            }
        }
    }

    public Long getRelationId() {
        return relationId;
    }

    public void setRelationId(Long relationId) {
        this.relationId = relationId;
    }

    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public Long getInterfaceId() {
        return interfaceId;
    }

    public void setInterfaceId(Long interfaceId) {
        this.interfaceId = interfaceId;
    }

    public String getInterfaceName() {
        return interfaceName;
    }

    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getDependRelationIds() {
        return dependRelationIds;
    }

    public void setDependRelationIds(String dependRelationIds) {
        this.dependRelationIds = dependRelationIds;
    }

    public String getDependRelationDesc() {
        return dependRelationDesc;
    }

    public void setDependRelationDesc(String dependRelationDesc) {
        this.dependRelationDesc = dependRelationDesc;
    }

    public String getDependParam() {
        return dependParam;
    }

    public void setDependParam(String dependParam) {
        this.dependParam = dependParam;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getQueryParam() {
        return queryParam;
    }

    public void setQueryParam(String queryParam) {
        this.queryParam = queryParam;
    }

    public String getBodyParam() {
        return bodyParam;
    }

    public void setBodyParam(String bodyParam) {
        this.bodyParam = bodyParam;
    }

    public String getPathParam() {
        return pathParam;
    }

    public void setPathParam(String pathParam) {
        this.pathParam = pathParam;
    }

    public Long getLoginConfigId() {
        return loginConfigId;
    }

    public void setLoginConfigId(Long loginConfigId) {
        this.loginConfigId = loginConfigId;
    }

    public String getLoginConfigDesc() {
        return loginConfigDesc;
    }

    public void setLoginConfigDesc(String loginConfigDesc) {
        this.loginConfigDesc = loginConfigDesc;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
